#include<iostream>
#include<cstdio>
using namespace std;
const int N = 1e6 + 10;
int arr[N];
int n;
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &arr[i]);
	}
	int ans = 1;
	for (int i = 1; i <= n; ) {
		int j = i + 1;
		while (j <= n) {
			int k = -1;
			int ans1 = 0;
			if ((j - i) & 1) {
				k = 1;
				ans1 = 1;
			}
			ans1 += (j - i) / 2;
			if (arr[j] == arr[i] +  k * ans1) {
				j++;
			}
			else {
				break;
			}
		}
		int k1 = j - i;
		ans = max(ans, k1);
		if (k1 > 1) {
			i += k1 - 1;
		}
		else {
			i++;
		}
		if (j >= n) {
			break;
		}
	}
	cout << ans << endl;
	return 0;
}